var storage = chrome.storage.local;
var btnSave = document.getElementById('btnSave');

var txtServerHost = document.getElementById('txtServerHost');
var txtServerPort = document.getElementById('txtServerPort');
var txtMessage = document.getElementById('txtMessage');

load();
btnSave.addEventListener('click', save);

function save(){
	config = {
			'host':	txtServerHost.value,
			'port':	txtServerPort.value,
	};
	if (config.host.length == 0 || config.port.length == 0) return;
	storage.set({'ServerConfig':config}, function(){
		txtMessage.innerText = 'Server Config saved';
	});
}

function load(){
	storage.get('ServerConfig', function(config){
		txtServerHost.value = config.ServerConfig.host || 'localhost';
		txtServerPort.value = config.ServerConfig.port || '8080';
	});
}